package com.etang.guosaia20201004.tools;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

import androidx.annotation.Nullable;

/**
 * 数据库
 */
public class MyDataBaseHelper extends SQLiteOpenHelper {

    public MyDataBaseHelper(@Nullable Context context, @Nullable String name, @Nullable SQLiteDatabase.CursorFactory factory, int version) {
        super(context, name, factory, version);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        //用户数据库
        db.execSQL("CREATE TABLE USER (_id INTEGER PRIMARY KEY AUTOINCREMENT,USERNAME TEXT,PASSWARD TEXT)");
        //传感器数据库
        db.execSQL("CREATE TABLE DATA (_id INTEGER PRIMARY KEY AUTOINCREMENT,DATA_NAME TEXT,DATA_NUMBER TEXT,TIME TEXT)");
        //默认插入数据
        db.execSQL("INSERT INTO USER (USERNAME,PASSWARD)VALUES(?,?)", new String[]{"Admin", "PassW0rd"});
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

    }
}
